function showTime(){
	//2020-09-24 09:15:11
	var d = new Date();
	var y = d.getFullYear();
	var mon = d.getMonth() + 1;
	var date = d.getDate();
	var h = d.getHours()
	var min = d.getMinutes()
	if(min <10) min = "0"+min;
	var s = d.getSeconds();
	if(s < 10) s = "0" + s;
	var t =  y + "-" + mon + "-" + date + " " + h + ":" + min + ":" + s
	document.getElementById("time").innerHTML = t;
	return t;
}

window.onload = function(){
	showTime()
	window.setInterval(showTime,1000)
	showImg()
	window.setInterval(showImg,4000)
	// 给数字li绑定事件
	var numsLis = document.getElementById("nums").getElementsByTagName("li");
	for(var i = 0; i < numsLis.length; i++){
		numsLis[i].onclick = function(){
			console.log(this.innerHTML)
			index = parseInt(this.innerHTML) - 1;
			showImg();
		}
	}
	
	
}

function soso(){
	//获取输入框的值
	var content= document.getElementById('content').value;
	alert("搜索的内容是：" + content)
}

var index = 0;
function showImg(){
	
	var imgsLis = document.getElementById("imgs").getElementsByTagName("li");

	var numsLis = document.getElementById("nums").getElementsByTagName("li");
	
	for(var i = 0; i < imgsLis.length; i++) {
		if(i == index){
			imgsLis[i].style.display = 'block';
			numsLis[i].style.backgroundColor = 'red';
		} else {
			imgsLis[i].style.display = 'none';
			numsLis[i].style.backgroundColor = '#808080';
		}
	}
	index ++;
	// 边界
	if(index == imgsLis.length){
		index = 0;
	}
}

$(function($){
	$.getJSON('http://127.0.0.1:8080/AdimgsServlet',{},function(data){
		console.log(data)
		
		if(data.length == 4){
			var content = ''
			for(var i=0; i<data.length; i ++){
				content = content + '<li><a href="' + data[i].img_page + '"><img src="http://127.0.0.1:8080/'+ data[i].img_url +'" alt="'+ data[i].img_desc +'"></a></li>'
			}
			
			document.getElementById('imgs').innerHTML =content;
			
		}
		
	});
});

function showTab(id){
	if(id == 'computer'){
		document.getElementById(id).style.display = 'block';
		document.getElementById('phone').style.display = 'none'
		document.getElementById('center_right_b_t').className = 'computer'
	}else {
		document.getElementById(id).style.display = 'block';
		document.getElementById('computer').style.display = 'none'
		document.getElementById('center_right_b_t').className = 'phone'
		
	}
}